package com.javaweb.controller;

import jakarta.validation.constraints.NotBlank;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * @desc:
 * @author: Ping
 * @date: 2024/11/20 11:22
 */
@Controller
public class SystemController {

    @GetMapping({"/", "/index"})
    public String index() {
        return "index" ;
    }

    @PostMapping("/sys/login")
    public String login(@RequestParam @NotBlank String username,
                        @RequestParam @NotBlank String password,
                        Model model) {

        if ( ! "123456".equals(password) ) {
            model.addAttribute("msg", "用户名或密码错误");
            return "error";
        }

        model.addAttribute("msg", "登录成功");
        model.addAttribute("user", username) ;
        return "welcome" ;



    }

}
